"""
Генератор базы паролей для брутфорса.

Author: Milinuri Nirvalen
Ver: 0.1 (2)
"""

from chiori import Plugin

p = Plugin(name='geт passwords', desc='создание базы паролей',
	admins=True, path='data/password_generator/')


# classes
# =======

class PassGen:

	def __init__(self):
		self.words = []
		self.b_days = []
		self.is_alive = True
		self.password_list = []
		self.suffix = [_ for _ in range(124)]

	def append(self, item, front=False):
		for _ in (item, item.lower(), item.title(), item.upper()):
			if _ in self.password_list:
				continue

			if front:
				self.password_list.insert(0, _)
			else:
				self.password_list.append(_)


	def append_data(self, args):

		if isinstance(args, str):
			args = [args]

		for data in args:

			# день рождения
			if data.count('-') == 3:
				if not data in self.b_days:
					self.b_days.append(data)

			# число
			elif data.isdigit():
				if not data in self.suffix:
					self.suffix.insert(0, data)
				self.append(data, front=True)

			# число с плавающей точкой
			elif len([_ for _ in data if _.isdigit()]) == (len(data) - 1):  # float
				if not data in self.suffix:
					self.suffix.insert(0, data)
					self.suffix.insert(0, ''.join([_ for _ in data if _.isdigit()]))

				self.append(data, front=True)
				self.append(''.join([_ for _ in data if _.isdigit()]), front=True)

			# слова
			elif data.isalpha():
				if not data.lower() in self.words:
					self.words.append(data)

			# символ
			elif len([_ for _ in data if not _.isalpha() and not _.isdigit()]) == len(data):
				if not data in self.suffix:
					self.suffix.insert(0, data)

			# пароль
			else:
				self.append(data, front=True)


	def generate(self):
		p.log('Создание списка паролей, это может занять время.')
		for suffix in self.suffix:
			for word in self.words:

				# слово + суффикс
				self.append(word)
				self.append(f'{word}{suffix}')
				self.append(f'{suffix}{word}')
				self.append(f'{suffix}{word}{suffix}')

				for bday in self.b_days:

					# переменные даты
					day = bday.split('-')[0]
					month = bday.split('-')[1]
					year = bday.split('-')[-1]
					plain_bday = bday.replace('-', '')

					self.append(plain_bday)
					self.append(f'{word}{year}')
					self.append(f'{word}{year[2:]}')
					self.append(f'{word}{plain_bday}')

					self.append(f'{day}{word}')
					self.append(f'{day[-1]}{word}')

					self.append(f'{year}{word}')
					self.append(f'{year[2:]}{word}')

					self.append(f'{month}{word}')
					self.append(f'{month[-1]}{word}')

					self.append(f'{month}{day}{word}')
					self.append(f'{month[-1]}{day}{word}')
					self.append(f'{month}{day[-1]}{word}')
					self.append(f'{month[-1]}{day[-1]}{word}')

					self.append(f'{day}{month}{word}')
					self.append(f'{day[-1]}{month}{word}')
					self.append(f'{day}{month[-1]}{word}')
					self.append(f'{day[-1]}{month[-1]}{word}')

					self.append(f'{month}{day}{word}{year}')
					self.append(f'{month}{day}{word}{year[2:]}')

					self.append(f'{month[-1]}{day}{word}{year}')
					self.append(
						f'{month[-1]}{day}{word}{year[2:]}')

					self.append(f'{month}{day[-1]}{word}{year}')
					self.append(
						f'{month}{day[-1]}{word}{year[2:]}')

					self.append(
						f'{month[-1]}{day[-1]}{word}{year}')
					self.append(
						f'{month[-1]}{day[-1]}{word}{year[2:]}')

					self.append(f'{month}{word}{suffix}')
					self.append(f'{month[-1]}{word}{suffix}')

					self.append(f'{day}{word}{suffix}')
					self.append(f'{day[-1]}{word}{suffix}')

					self.append(f'{suffix}{word}{month}')
					self.append(f'{suffix}{word}{month[-1]}')

					self.append(f'{suffix}{word}{day}')
					self.append(f'{suffix}{word}{day[-1]}')

					self.append(f'{suffix}{word}{year}')
					self.append(f'{suffix}{word}{year[2:]}')

		return self.password_list


@p.command('<g(en) p/password(s)>')
async def passwordGenerator(event, ctx):
	path = p.dpath+ctx.strtime+'.txt'
	pg = PassGen()
	text = ''

	if ctx.args:
		text += f'\n[*] вложено: {len(ctx.args)} аргументов'
		pg.append_data(ctx.args)

		res = pg.generate()

		with open(path, 'w') as f:
			f.write('\n'.join(res))
			text += f'\n[*] {path}: записано {len(res)} паролей'
		await ctx.message(text)

	else:
		await ctx.message('Укажите ключевое словл, имя, пароль, номер, символ, или дату(dd-mm-yyy)')
